package com.lelv.framework.tag;

import java.io.IOException;
import java.io.Writer;

import org.apache.struts2.components.Component;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.lelv.framework.bo.IBaseDictBo;
import com.opensymphony.xwork2.util.ValueStack;

public class DictInputComponent extends Component{

	private String dictField;
	private String dictKey;
	private IBaseDictBo baseDictBo;

	public DictInputComponent(ValueStack stack) {
		super(stack);
		// TODO Auto-generated constructor stub
	}

	public String getDictField() {
		return dictField;
	}

	public void setDictField(String dictField) {
		this.dictField = dictField;
	}

	public String getDictKey() {
		return dictKey;
	}

	public void setDictKey(String dictKey) {
		this.dictKey = dictKey;
	}

	@Override
	public boolean start(Writer writer) {
		// TODO Auto-generated method stub
		boolean result = super.start(writer);
		try {

			ApplicationContext factory = new FileSystemXmlApplicationContext("D:\\EclipseWorkSpace\\lelv\\web\\WEB-INF\\applicationContext.xml");

			baseDictBo = (IBaseDictBo) factory.getBean("baseDictBo");
			writer.write(baseDictBo.getDictValue(dictField, dictKey));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public IBaseDictBo getBaseDictBo() {
		return baseDictBo;
	}

	public void setBaseDictBo(IBaseDictBo baseDictBo) {
		this.baseDictBo = baseDictBo;
	}
}
